var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("Game"),
    l = e("ObjectPool"),
    _ = e("RoleSoldierInfo"),
    c = e("node_team"),
    d = e("soldier_node"),
    h = e("team_node_info"),
    u = cc._decorator,
    p = u.ccclass,
    m = u.property,
    f = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.team_type = s.TeamInfo.left_team),
                (t.role_soldier_view = null),
                (t.add_num = 0),
                (t.soldier_list = [s.SoldierType.near_soldier, s.SoldierType.far_soldier, s.SoldierType.far_soldier]),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.addEvent = function () {
                this.attachEvent(n.default.SEND_CREATE_SOLDIER_INFO, this.showAddSoldier, this),
                    this.attachEvent(n.default.SEND_CREATE_MONSTER_SOLDIER_INFO, this.createMonster, this);
            }),
            (t.prototype.showAddSoldier = function () {
                var e = this;
                if (i.GlobalParams.GameStart)
                    if (
                        (this.createSoldier(this.soldier_list[this.add_num]),
                            this.add_num++,
                            this.add_num < this.soldier_list.length)
                    )
                        this.scheduleOnce(function () {
                            e.showAddSoldier();
                        }, 3);
                    else {
                        for (var t = 0; t < 3; t++)
                            2 == i.GlobalParams.GameDestroyTower[this.team_type == s.TeamInfo.left_team ? 1 : 0][t] &&
                                this.createSuperSoldier(t);
                        this.add_num = 0;
                    }
            }),
            (t.prototype.createSoldier = function (e) {
                for (var t = l.default.getInstance().creatPlane(s.Pool_Type.soldier), o = 0; o < 3; o++) {
                    var a = cc.instantiate(t),
                        n = { team: this.team_type, info: _.default.soldier_info[e], id: e };
                    a.getComponent(h.default).setNodeInfo(n),
                        (a.name = "soldier_team_" + this.team_type),
                        a.getComponent(c.default).setTeamInfo(this.team_type),
                        a.getComponent(d.default).showSoldierPos(o, this.team_type),
                        (a.active = !0),
                        a.setParent(this.role_soldier_view);
                }
            }),
            (t.prototype.createSuperSoldier = function (e) {
                var t = l.default.getInstance().creatPlane(s.Pool_Type.super_soldier),
                    o = cc.instantiate(t),
                    a = {
                        team: this.team_type,
                        info: _.default.soldier_info[s.SoldierType.super_soldier],
                        id: s.SoldierType.super_soldier
                    };
                o.getComponent(h.default).setNodeInfo(a),
                    (o.name = "soldier_team_" + this.team_type),
                    o.getComponent(c.default).setTeamInfo(this.team_type),
                    o.getComponent(d.default).showSoldierPos(e, this.team_type),
                    (o.active = !0),
                    o.setParent(this.role_soldier_view);
            }),
            (t.prototype.createMonster = function (e, t) {
                var o = t;
                if (o.team == this.team_type) {
                    var a = null;
                    a =
                        o.id == s.SoldierType.dragon_soldier
                            ? cc.instantiate(r.default.getInstance().getFightPrefab("dragon_soldier"))
                            : cc.instantiate(r.default.getInstance().getFightPrefab("super_dragon_soldier"));
                    var n = { ma_hp: 0, ma_attack: 0, ma_frequency: 0.65, ma_speed: 30, ma_range: 250 };
                    (n.ma_hp = _.default.moster_info[o.id].hp[o.level]),
                        (n.ma_attack = _.default.moster_info[o.id].attack[o.level]);
                    var i = { team: o.team, info: n, id: o.id };
                    a.getComponent(h.default).setNodeInfo(i), (a.name = "monster_" + o.team);
                    var l = this.node.getPosition();
                    (l.y -= 100),
                        a.setPosition(l),
                        a.getComponent(c.default).setTeamInfo(this.team_type),
                        (a.active = !0),
                        a.setParent(this.role_soldier_view);
                }
            }),
            oo([m({ type: cc.Enum(s.TeamInfo) })], t.prototype, "team_type", void 0),
            oo([m(cc.Node)], t.prototype, "role_soldier_view", void 0),
            oo([p], t)
        );
    })(a.default);
o.default = f;
